package org.jeecg.modules.iot.controller;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.iot.model.power.TaiPower;
import org.jeecg.modules.iot.mqtt.server.service.processor.powerOperate.PowerService;
import org.jeecg.modules.iot.service.IPowerService;
import org.jeecg.modules.rental.entity.RentalEBike;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/iot/bms")
@Api(tags = "电池控制层")
public class BMSController {

    @Autowired
    IPowerService powerService;

    @Autowired
    PowerService powersService;

    @GetMapping("/queryBMSPower/{imei}/{sn}")
    public  Integer queryPower(@PathVariable String imei, @PathVariable String sn) {
        RentalEBike car=new RentalEBike();
        car.setCarCode(imei);
        car.setPhone(sn);
        Integer seq=powersService.queryPower(car);
        return seq; // 直接使用Feign客户端调用
    }


    @GetMapping("/setContinuousVoltage/{imei}/{sn}")
    public  Integer setContinuousVoltage(@PathVariable String imei, @PathVariable String sn, @RequestParam Boolean isContinuousVoltage) {
        RentalEBike car = new RentalEBike();
        car.setCarCode(imei);
        car.setPhone(sn);
        return powersService.setContinuousVoltage(car, isContinuousVoltage); // Feign客户端调用
    }

    @PostMapping("/queryDeviceId/{imei}/{sn}")
    public Integer queryDeviceId(@PathVariable String imei, @PathVariable String sn) {
        RentalEBike car = new RentalEBike();
        car.setCarCode(imei);
        car.setPhone(sn);
        return powersService.getDeviceSN(car); // Feign客户端调用
    }

  /*  @PostMapping("/setPower/{imei}/{sn}")
    public Result<Integer> setPower(@PathVariable String imei, @PathVariable String sn, @RequestParam Boolean powerOffMode, @RequestParam int currentLimit, @RequestParam int timeLimit) {
        return controlAPI.setPower(imei, sn, powerOffMode, currentLimit, timeLimit); // Feign客户端调用
    }

    @PostMapping("/queryDeviceId/{imei}/{sn}")
    public Result<Integer> queryDeviceId(@PathVariable String imei, @PathVariable String sn) {
        return controlAPI.queryDeviceId(imei, sn); // Feign客户端调用
    }*/

    @GetMapping("/queryTaiPowerLastByDeviceId/{imei}")
    public Result<TaiPower> queryTaiPowerLastByDeviceId(@PathVariable String imei ) {
        // 从请求中获取deviceId
        String deviceId = imei; //或其他获取deviceId的方式
        TaiPower taiPower = powerService.queryLastByDeviceId(deviceId);
        return Result.OK(taiPower);
    }
}
